#!/bin/python3
# -*- coding: utf-8 -*-
# 测试一个经典的GUI程序的写法，使用面对对象的方式

import tkinter as tk
from tkinter import messagebox


class Application(tk.Frame):
    """一个经典的GUI程序的类的写法"""
    i = 1

    def __init__(self, master=None):
        super().__init__(master)
        self.master = master
        self.pack()
        self.createWidget()

    def createWidget(self):
        """创建组件"""
        self.w = tk.Entry(self)
        self.w.pack()
        self.btn01 = tk.Button(self)
        self.btn01['text'] = '点击送花'
        self.btn01.pack()
        self.btn01['command'] = self.songhua

        # 创建一个退出按钮
        self.btnQuit = tk.Button(self, text='退出', command=root.destroy)
        self.btnQuit.pack()
        self.t = tk.Text(self, width=30, height=8, font=("SimHei", 18), selectforeground='red',
                         state=tk.DISABLED)  # 显示多行文本
        self.t.place(x=70, y=280)
        self.t.pack()

    def songhua(self):
        messagebox.showinfo('送花', '送你99朵花')
        self.t['state'] = tk.NORMAL
        self.t.insert('end', 'jieguo{0}'.format(self.i))  # insert & end   标记为在光标处和最后
        self.t['state'] = tk.DISABLED
        self.i += 1


if __name__ == '__main__':
    root = tk.Tk()
    root.geometry('400x500+200+300')
    root.title('一个经典的GUI程序类的测试')
    app = Application(master=root)
    root.mainloop()
